<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        .div {
            width: 400px;
            margin: 0 auto;
        }

        .div div {
            display: inline-block;
            /* width: 40px; */
            height: 40px;
            background-color: black;
            line-height: 40px;
            text-align: center;
            font-size: 1.25rem;
            color: aliceblue;
            padding:0 5px;
        }
    </style>
</head>

<body>
    <div class="div">
        <div>天</div>
        <div>时</div>
        <div>分</div>
        <div>秒</div>
    </div>
    <script>
        var div = document.querySelector('.div')
        var divs = div.children
        // console.log(divs[1]);
        setInterval(getDates,1000)
        var intime = +new Date('2023-04-05 15:35:00');
        getDates();
        function getDates() {
            var time = +new Date();
            if (time < intime) {
                var settime = (intime - time) / 1000;//总毫秒数 //总毫秒数除以1000等于总秒数
                // console.log(settime);
                var t = parseInt(settime / 60 / 60 / 24); //天数
                t = t < 10 ? '0' + t : t;
                divs[0].innerHTML=t+'天'
                var h = parseInt(settime / 60 / 60 %24 ); //时
                h = h < 10 ? '0' + h : h;
                divs[1].innerHTML=h+'时'
                var m = parseInt(settime / 60 % 60); //分
                m = m < 10 ? '0' + m : m;
                divs[2].innerHTML=m+'分'
                var s = parseInt(settime % 60); //秒
                s = s < 10 ? '0' + s : s;
                divs[3].innerHTML=s+'秒'
            } else {
                return  new Date();
            }

            // return t + '天' + h + '时' + m + '分' + s + '秒';
        }
      
    </script>
</body>

</html>